package com.flyduck.mall.cms.dubbo;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.flyduck.mall.cms.api.RemoteCartItemService;
import com.flyduck.mall.cms.domain.CmsCartItem;
import com.flyduck.mall.cms.mapper.CmsCartItemMapper;
import com.flyduck.mall.cms.api.vo.RemoteCartItemRespVO;
import com.flyduck.mall.common.core.utils.BeanUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * RemoteCartItemServiceImpl
 * </p>
 *
 * @author flyduck
 * @since 2024-07-23
 */
@Service
@DubboService
public class RemoteCartItemServiceImpl implements RemoteCartItemService {

    @Resource
    private CmsCartItemMapper cmsCartItemMapper;

    @Override
    public List<RemoteCartItemRespVO> getCartItemListByIds(List<Long> ids) {
        List<CmsCartItem> cmsCartItemList = cmsCartItemMapper.selectList(
                new LambdaQueryWrapper<CmsCartItem>()
                        .in(CmsCartItem::getId, ids)
                        .orderByDesc(CmsCartItem::getCreateTime)
        );
        return BeanUtils.toBeanList(cmsCartItemList,RemoteCartItemRespVO.class);
    }

    @Override
    public void deleteByIds(List<Long> ids) {
        cmsCartItemMapper.deleteBatchIds(ids);
    }
}
